package cn.manager.travel.web.servlet;

import cn.manager.travel.domain.Laboratory;
import cn.manager.travel.domain.Major;
import cn.manager.travel.domain.New;
import cn.manager.travel.domain.Teacher;
import cn.manager.travel.service.ClientService;
import cn.manager.travel.service.impl.ClientServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@WebServlet("/client/*")
public class ClientServlet extends BaseServlet{
	
	private ClientService clientService = new ClientServiceImpl();
	
	public void showNewList(HttpServletRequest request, HttpServletResponse response) throws Exception {
		List<New> list = clientService.showNewList();
		request.setAttribute("newList",list);
		request.getRequestDispatcher("/news_list.jsp").forward(request,response);
	}
	
	public void showNew(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String nID = request.getParameter("nID");
		New n = clientService.showNew(nID);
		request.setAttribute("n",n);
		request.getRequestDispatcher("/new_details.jsp").forward(request,response);
	}
	public void showMajorList(HttpServletRequest request, HttpServletResponse response) throws Exception {
		List<Major> majors = clientService.showMajorList();
		request.setAttribute("majorList",majors);
		request.getRequestDispatcher("/majors_list.jsp").forward(request,response);
	}
	
	public void showMajor(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String mID = request.getParameter("mID");
		Major m = clientService.showMajor(mID);
		request.setAttribute("m",m);
		request.getRequestDispatcher("/major_details.jsp").forward(request,response);
	}
	
	public void showTeacher(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String tID = request.getParameter("tID");
		Teacher t = clientService.showTeacher(tID);
		request.setAttribute("t",t);
		request.getRequestDispatcher("/teacher_details.jsp").forward(request,response);
	}
	
	public void showLaboratory(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String lID = request.getParameter("lID");
		Laboratory l = clientService.showLaboratory(lID);
		request.setAttribute("l",l);
		request.getRequestDispatcher("/laboratory_details.jsp").forward(request,response);
	}
}
